// Example.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[]) {

	FILE *fp_in = NULL, *fp_out = NULL, *fp_sample;
	fp_in = fopen("E:\\Projects\\Example\\debug\\5th", "rb");
	fp_sample = fopen("E:\\Projects\\Example\\debug\\_Samples.rar", "rb");
	fp_out = fopen("E:\\Projects\\Example\\debug\\5th.rar", "wb");

	if(fp_sample == NULL)
		return 0;
	fseek(fp_sample, 0, SEEK_END);
	long length = ftell(fp_sample);
	char *buff = NULL;
	buff = new char[length];
	rewind(fp_sample);
	fread(buff, sizeof(char), length, fp_sample);
	fwrite(buff, sizeof(char), length, fp_out);
	delete []buff;

	if((fp_in != NULL) && (fp_out != NULL)) {
		fseek(fp_in, 0, SEEK_END);
		long end_pos = ftell(fp_in);
		rewind(fp_in);
		char *buff = NULL;
		buff = new char[end_pos];
		fread(buff, sizeof(char), end_pos, fp_in);
		for(int i=0; i<end_pos; i++)
			buff[i] = ~buff[i];
		fwrite(buff, sizeof(char), end_pos, fp_out);
		delete []buff;
		fclose(fp_in);
		fclose(fp_out);
	}

	system("pause");
	return 0;
}